package com.project.fortuneteller.mappers;

import com.project.fortuneteller.pojo.User;
import com.project.fortuneteller.pojo.dto.UserImgDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper{

    @Select("select * from user where id = #{id}")
    User getById(@Param("id") int id);

    @Select("select user_name from user where id = #{id}")
    String getUserNameById(@Param("id") int id);


    @Select("select * from user where user_name like #{nickStr}")
    List<User> getByUsername(@Param("nickStr") String nickStr);

    @Select("select * from user where email= #{email}")
    User getByEmail(@Param("email") String email);


    @Select("select * from user where password= #{password}")
    User getByPassword(@Param("password") String password);

    @Insert("insert into user (user_name,password,email) values( #{userName},#{password},#{email})")
    void insert(User user);

    @Update("update user set avatar = #{avatar}  where id = #{id}")
    void insertUserAvatar(String avatar, Integer id);

    // 获取 用户的 照片信息
    @Select("select avatar, avatar_image_url ,id from user where id = #{id}")
    UserImgDTO getUserAvatar(Integer id);

    // 编辑修改
    @Update("update user set career=#{career}, email=#{email},gender=#{gender}, age=#{age}, signature=#{signature} where id=#{id}")
    int editorInsert(User user);

}
